<?php

class SubController extends Controller
{
	public $layout='//layouts/main';
	public function actionIndex($key=null,$ajax=null)
	{
		$keyCategories = "";
		$aliasKey = $key;
		$arrKey = explode("/",$key);
		if(!empty($arrKey)){
			foreach($arrKey as $key=>$value){
				if($key== count($arrKey)-1){
					$keyCategories = $value;
				}
			}
		}
		// dump($keyCategories,false);
		$key = $keyCategories;
		$category = Gadgetcategory::model()->findByAttributes(array(
			'urlKey'=>$key
		));
		$subCat = array();
		$nameCategory = null;
		$keyCategory = null;
		if(!empty($category)){
			$subCat = Gadgetcategory::model()->findAllByAttributes(array(
				'isActive'=>1,
				'parentCategoryId'=>$category->id
			));
			$nameCategory = $category->name;
			$keyCategory = $category->urlKey;
		}
		if($ajax!=null){
			$this->layout = "ajax";
			$this->render('_index',array(
				'subCat'=>$subCat,
				'nameCategory'=>$nameCategory,
				'keyCategory'=>$keyCategory,
			));
		
		}else{
			$this->render('index',array(
				'subCat'=>$subCat,
				'nameCategory'=>$nameCategory,
				'keyCategory'=>$keyCategory,
				'keyCategories'=>$keyCategories,
				'aliasKey'=>$aliasKey,
			));
		}
		
	}
	
}